package com.ihr360.excel.entity;

import com.ihr360.commons.model.entity.StringIdWithTimeAndCompanyId;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 电子表格 行数据
 *
 * @author richey
 */
public class CorrectSpreadsheetRowEntity extends StringIdWithTimeAndCompanyId {

    private static final long serialVersionUID = -2879138799574402385L;


    private SpreadSheetEntity sheet;

    /**
     * 员工Id
     */
    private String staffId;

    /**
     * 姓名
     */
    private String staffName;

    /**
     * 手机号码
     */
    private String mobileNo;

    /**
     * 行号
     */
    private Integer rowNum;

    /**
     * 是否有权限导入
     */
    private Boolean hasPermission = false;


    /**
     * Excel行数据内容，保存内容为表头与行数据的Map映射对象
     */
    private Map<String, Object> data;

    public SpreadSheetEntity getSheet() {
        return sheet;
    }

    public void setSheet(SpreadSheetEntity sheet) {
        this.sheet = sheet;
    }

    public String getStaffId() {
        return staffId;
    }

    public void setStaffId(String staffId) {
        this.staffId = staffId;
    }

    public String getStaffName() {
        return staffName;
    }

    public void setStaffName(String staffName) {
        this.staffName = staffName;
    }

    public String getMobileNo() {
        return mobileNo;
    }

    public void setMobileNo(String mobileNo) {
        this.mobileNo = mobileNo;
    }

    public Integer getRowNum() {
        return rowNum;
    }

    public void setRowNum(Integer rowNum) {
        this.rowNum = rowNum;
    }

    public Boolean getHasPermission() {
        return hasPermission;
    }

    public void setHasPermission(Boolean hasPermission) {
        this.hasPermission = hasPermission;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        if (MapUtils.isEmpty(data) || sheet == null || CollectionUtils.isEmpty(sheet.getDateHeaders())) {
            this.data = data;
            return;
        }
        List<String> dateHeaders =  sheet.getDateHeaders();
        data.forEach((header,value) -> {
            if (value != null && value instanceof Long && dateHeaders.contains(header)) {
                data.put(header, new Date((Long) value));
            }
        });
        this.data = data;
    }

    @Override
    public String toString() {
        return "CorrectSpreadsheetRowEntity{" +
                "sheet=" + sheet +
                ", staffId='" + staffId + '\'' +
                ", staffName='" + staffName + '\'' +
                ", mobileNo='" + mobileNo + '\'' +
                ", rowNum=" + rowNum +
                ", hasPermission=" + hasPermission +
                ", data=" + data +
                ", createdAt=" + createdAt +
                ", updatedAt=" + updatedAt +
                ", id='" + id + '\'' +
                '}';
    }
}